import { defineConfig, ConfigEnv, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from 'path';

// https://vitejs.dev/config/
export default defineConfig(({ mode, command }: ConfigEnv) => {
   // 环境切换问题
   const env = loadEnv(mode, process.cwd());
  return {
    plugins: [uni()],
    resolve: {
      alias: {
        // 设置路径
        '~': path.resolve(__dirname, './'),
        // 设置别名
        '@': path.resolve(__dirname, './src'),
      },
    },
    css: {
      preprocessorOptions: {  
        scss: {  
        // 取消sass废弃API的报警
        silenceDeprecations: ['legacy-js-api', 'color-functions', 'import'],  
        },  
      },  
	},
    server: {
      // 允许IP访问
      host: "0.0.0.0",
      // 应用端口 (默认:3000)
      port: Number(env.VITE_APP_PORT),
      // 运行是否自动打开浏览器
      open: false,
    }
  }
});
